package karaoke.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Evento;
import karaoke.negocio.GestionEvento;

/**
 * Servlet implementation class LocalInsertarServlet
 */
@WebServlet("/EventoInsertarServlet")
public class EventoInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public EventoInsertarServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String nombre = request.getParameter("txtNombre");
		String fecha = request.getParameter("txtFecha");
		String hora = request.getParameter("txtHora");
		String aforo = request.getParameter("txtAforo");
		String descripcion = request.getParameter("txtDescripcion");
		String idReserva = request.getParameter ("txtReserva_id"); 
		
		Evento evento = new Evento();
		evento.setNombre_Evento(nombre);
		evento.setFecha_Evento(fecha);
		evento.setHora_Evento(hora);
		evento.setAforo_Evento(Integer.parseInt(aforo));
		evento.setDescripcion_Evento(descripcion);
		evento.setReserva_idReserva(Integer.parseInt(idReserva));
                

		GestionEvento negocio = new GestionEvento();
		try {
			negocio.insertar(evento);
			response.sendRedirect(request.getContextPath()+ "/EventoBuscar.jsp");
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp");
			rd.forward(request, response);
		}
	}

}